#ifndef SELECTIONMATERIALSWITCHER_H
#define SELECTIONMATERIALSWITCHER_H

#include <Ogre.h>
#include "SelectionBuffer.h"

using namespace Ogre;

class SelectionBuffer;

struct cmp_ColourValue
{
	bool operator()(const ColourValue &a, const ColourValue &b) const
	{
		return a.getAsBGRA() < b.getAsBGRA();
	}
};

class SelectionMaterialSwitcher : public MaterialManager::Listener
{
private:
	typedef std::map<ColourValue, Ogre::String, cmp_ColourValue> ColorMap;
	typedef std::map<ColourValue, Ogre::String, cmp_ColourValue>::const_iterator ColorMapConstIter;

	Ogre::String       mEmptyString;
	Ogre::ColourValue  mCurrentColor;
	Ogre::String       mLastEntity;
	Ogre::Technique   *mLastTechnique;
	SelectionMaterialSwitcher::ColorMap mColorDict;

	void getNextColor();


//  friend SelectionBuffer;
public:
	SelectionMaterialSwitcher();
	~SelectionMaterialSwitcher();

	std::vector<Renderable*> mBlackList;

	virtual Technique *handleSchemeNotFound(unsigned short schemeIndex, const Ogre::String &schemeName,
	                                        Material *originalMaterial, unsigned short lodIndex,
	                                        const Renderable *rend);
	const Ogre::String &getEntityName(const ColourValue &color) const;
	void reset();
};

#endif
